<?php
require_once '../config/config.php';
require_once '../config/connexion_db.php';
?>
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="utf-8">
        <title>Liste des contacts</title>
        <link href="../bootstrap/css/bootstrap.css" type="text/css" rel="stylesheet">
        <link href="../css/style.css" type="text/css" rel="stylesheet">
        
    </head>
    <body><a id="haut"></a>
        
        <?php require_once "../config/css_js_bootstrap/css_js_bootstrap.php"; 
         
        require_once '../config/menus/menu_principal.php';
        
        
        $id = isset($_GET['id']) ? $_GET['id'] : "";
        if(isset($_GET["id_entreprise"])) {
        $id_entreprise = $_GET["id_entreprise"];
        $sql = "SELECT * FROM  entreprises, contacts WHERE entreprises.id = contacts.id_entreprise AND id_entreprise='$id_entreprise' ";
        }
        elseif(isset($_GET["tous"])) {
        $sql = "SELECT * FROM entreprises, contacts WHERE entreprises.id = contacts.id_entreprise";
        }
        elseif(isset($_GET['croissant'])) {
        $sql = "SELECT * FROM entreprises, contacts  WHERE entreprises.id = contacts.id_entreprise ORDER BY nom ASC, prenom ASC";
        }
        elseif(isset($_GET["decroissant"])) {
        $sql = "SELECT * FROM entreprises, contacts WHERE entreprises.id = contacts.id_entreprise ORDER BY nom DESC, prenom DESC";
        }
        else {
             $sql = "SELECT * FROM entreprises, contacts WHERE entreprises.id = contacts.id_entreprise"; 
        }
        
        
        $envoi_requete = mysqli_query($connexion_serveur, $sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());

        $nbre= mysqli_num_rows($envoi_requete);

        ?> 
        <br><div id="div2">
                <h3>LISTE DES CONTACTS</h3>
            Nombre de contacts affichés :     <span><?php echo $nbre; ?></span>
        </div><br>
        <br>
        <div id="div2">
            <form>
                <input class="btn btn-default" type="button" value="Afficher tous" onclick="window.location.href='../contacts/liste_contacts.php?tous'">
                <input class="btn btn-default" type="button" value="Afficher tous croissant" onclick="window.location.href='../contacts/liste_contacts.php?croissant'">
                <input class="btn btn-default" type="button" value="Afficher tous décroissant" onclick="window.location.href='../contacts/liste_contacts.php?decroissant'">
            </form>
            <br>
         
             </div>
<?php        

    

    
while($resultats = mysqli_fetch_array($envoi_requete)) { 

              ?>
            <div id="div1">
        <table>
            <tr>
                <td class="col1"> n°</td>
                <td class="col2"><?php echo $resultats['id']; ?></td>
            </tr>
            <tr>
                 <td class="col1">Nom et prénom</td>
                 <td class="col2"><?php echo $resultats['nom']?>  <?php echo $resultats['prenom'];  ?></td>
            </tr>
            <tr>
                 <td class="col1">Entreprise</td>
                 <td class="col2"><?php echo $resultats['raison_sociale']; ?></td>
            </tr>
            <tr>
                 <td class="col1">Téléphone</td>
                 <td class="col2"><?php echo $resultats['telephone'];  ?></td>
            </tr>
            <tr>
                 <td class="col1">Photo</td>
                 <td class="col2"><?php echo $resultats['photo'];  ?></td>
            </tr>
            <tr>
                 <td class="col1">Email</td>
                 <td class="col2"><?php echo $resultats['email'];  ?></td>
            </tr>
            <tr>
                 <td class="col1">Photo</td>
                 <td class="col2" id="imag"><img src="<?php echo CHEMIN; ?><?php echo $resultats['photo'];  ?>"></td>
            </tr>
            <tr>
                 <td class="col1">Observations</td>
                 <td class="col2"><?php echo $resultats['observations'];  ?></td>
            </tr>
            <tr>
                <td class="col1"></td>
                <td class="col2"> <a href="../contacts/modifier_contacts.php?id=<?php echo $resultats['id'];?>" >Modifier</a></td>
            </tr>
            </table>
                <br>
           </div>
            <?php
            }
        ?>
        <div ><a href="#haut">Haut de page</a>
        <br>
        </div>
        <br>
    </body>
</html>
